package org.zhs.a_11_内部类.迭代器;

/**
 * @Author: zhs
 * @Date: 2024/9/11 20:26
 * @Version: 1.0
 * @Description:
 */
public class Sequence {

    private Object[] items;

    private int next = 0;

    public Sequence(int size){
        items = new Object[size];
    }

    public void add(Object data){
        if(next < items.length){
            items[next++] = data;
        }
    }


    private class SequenceSelector implements Selector{
        private int i = 0;

        @Override
        public boolean end() {
            return i == items.length;
        }

        @Override
        public Object current() {
            return items[i];
        }

        @Override
        public void next() {
            if(i < items.length){
                i++;
            }
        }

    }



    public Selector selector(){
        return new SequenceSelector();
    }

}
